import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class MyHistoryPanel extends JPanel{

	JScrollPane scroller;
	ArrayList<JLabel> orderlist;
	ArrayList<JButton> commitlist;
	JPanel content;
	
	public MyHistoryPanel(){
	  	setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		setBorder (BorderFactory.createTitledBorder(
				BorderFactory.createEtchedBorder (), "Order History"));
	  	content = new JPanel();
	  	content.setLayout(new GridLayout(30, 1, 10, 10));
	  	
		scroller = new JScrollPane(content);
		scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
	  	
	  	add(scroller);
	  	
	  	orderlist = new ArrayList<JLabel> ();
	  	commitlist = new ArrayList<JButton> ();
	}
	
	public void addHistory(UpgradeOrder theOrder){
		  JPanel thePanel;
		  JLabel order;
		  JButton commit;
		  
		  thePanel = new JPanel();
		  thePanel.setLayout(new GridLayout(1, 2, 10, 10));
		  	  
		  order = new JLabel(theOrder.printOrder());
		  commit = new JButton("Commit");
		  orderlist.add(order);
		  commitlist.add(commit);
		  
		  thePanel.add(order);
		  thePanel.add(commit);
		  
		  content.add(thePanel);
		  commit.addActionListener(new commitListener(commit)); 
		  
		  //send the order to the server
	}
	
	public void addHistory(Order theOrder){
		  JPanel thePanel;
		  JLabel order;
		  JButton commit;
		  
		  thePanel = new JPanel();
		  thePanel.setLayout(new GridLayout(1, 2, 10, 10));
		  	  
		  order = new JLabel(theOrder.printOrder());
		  commit = new JButton("Commit");
		  orderlist.add(order);
		  commitlist.add(commit);
		  
		  thePanel.add(order);
		  thePanel.add(commit);
		  
		  content.add(thePanel);
		  commit.addActionListener(new commitListener(commit)); 
		  
		  //send the order to the server
	}
	
	class commitListener implements ActionListener{
		private JButton button;
		public commitListener(JButton _button){
			button = _button;
		}
		public void actionPerformed(ActionEvent arg0) {
			  button.setEnabled(false);
			
		}
		
	}
}
